//
//  AppleScriptStream.m
//  Pennyworth Punch Clock
//
//  Created by Chris Karr on 7/24/08.
//  Copyright 2008 Northwestern University. All rights reserved.
//

#import "AppleScriptStream.h"
#import "AppleScriptSlice.h"

@implementation AppleScriptStream

@synthesize name;
@synthesize object;

- (NSArray *) getSlices
{
	NSMutableArray * asSlices = [NSMutableArray array];
	
	NSSortDescriptor * sort = [[NSSortDescriptor alloc] initWithKey:@"startDate" ascending:YES];
	
	NSArray * slices = [[self.object mutableSetValueForKey:@"slices"] allObjects];
	
	for (NSManagedObject * slice in [slices sortedArrayUsingDescriptors:[NSArray arrayWithObject:sort]])
	{
		AppleScriptSlice * asSlice = [[AppleScriptSlice alloc] init];
		asSlice.name = [slice valueForKey:@"name"];
		asSlice.startDate = [slice valueForKey:@"startDate"];
		asSlice.endDate = [slice valueForKey:@"endDate"];
		
		asSlice.stream = self;

		[asSlices addObject:asSlice];
	}
	
	return asSlices;
}

- (NSScriptObjectSpecifier *) objectSpecifier 
{
	NSScriptObjectSpecifier * containerRef = [NSApp objectSpecifier];
	
	return [[NSNameSpecifier alloc] initWithContainerClassDescription:[containerRef keyClassDescription] 
												   containerSpecifier:containerRef
																  key:@"streams" 
																 name:self.name];
}

@end
